package P5;

import java.io.*;
import java.net.*;


/**
 * 5.1完成10086在线客服人工咨询模拟功能
 * 5.1.2客户端的代码：
 */
public class Client {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 9999);

            BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            String inputLine;
            while ((inputLine = userInput.readLine()) != null) {
                out.println(inputLine);
                if (inputLine.equals("bye")) {
                    break;
                }
                System.out.println("Server: " + in.readLine());
            }

            userInput.close();
            in.close();
            out.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}